package com.suypower.carManage.action;

import javax.servlet.ServletException;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

public class RefuelAction extends ActionSupport {

	private String id;
	private String car_code;
	private String type;
	private String money;
	private String quantity;
	private String ref_date;
	private String driver;
	private String card_code;
	private String ref_price;
	private String ref_area;
	private String yard;
	private String remark;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCar_code() {
		return car_code;
	}

	public void setCar_code(String carCode) {
		car_code = carCode;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getMoney() {
		return money;
	}

	public void setMoney(String money) {
		this.money = money;
	}

	public String getQuantity() {
		return quantity;
	}

	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}

	public String getRef_date() {
		return ref_date;
	}

	public void setRef_date(String refDate) {
		ref_date = refDate;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getCard_code() {
		return card_code;
	}

	public void setCard_code(String cardCode) {
		card_code = cardCode;
	}

	public String getRef_price() {
		return ref_price;
	}

	public void setRef_price(String refPrice) {
		ref_price = refPrice;
	}

	public String getRef_area() {
		return ref_area;
	}

	public void setRef_area(String refArea) {
		ref_area = refArea;
	}

	public String getYard() {
		return yard;
	}

	public void setYard(String yard) {
		this.yard = yard;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String execute() {
		String res = "";
		DAO dao = new DAO();
		String sql = "";
		if (id != null && !id.equals("")) {
			sql = "UPDATE tb_refuel  SET  car_code = '" + car_code
					+ "',  type = '" + type + "',  money = '" + money
					+ "',  quantity = '" + quantity + "',  ref_date = '"
					+ ref_date + "',  driver = '" + driver
					+ "',  card_code = '" + card_code + "',  ref_price = '"
					+ ref_price + "',  ref_area = '" + ref_area
					+ "',  yard = '" + yard + "',  remark = '" + remark
					+ "' where id=" + id;

		} else {

			sql = "INSERT INTO tb_refuel(car_code,type,money,quantity,ref_date,driver,card_code,ref_price,ref_area,yard,remark)VALUES('"
					+ car_code
					+ "','"
					+ type
					+ "',"
					+ money
					+ ","
					+ quantity
					+ ","
					+ ref_date
					+ ",'"
					+ driver
					+ "','"
					+ card_code
					+ "','"
					+ ref_price
					+ "','"
					+ ref_area
					+ "',"
					+ yard
					+ ",'"
					+ remark + "')";
		}
		int count = 0;
		try {
			count = dao.execCommand(ConstUtil.DBNAME, sql);
			if (count > 0) {
				res = this.SUCCESS;
			} else {
				res = this.ERROR;
			}
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}
}
